package com.example.springcloud.common;

import lombok.Data;

/**
 * @author 莫磊
 * @date 2025/8/20
 * @description 返回结果的封装类
 */
@Data
public class ResponseEntity<T> {

    private String code;
    private String message;
    private T data;

    private ResponseEntity(String code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }


    private static <T> ResponseEntity<T> success(String code, String message, T data) {
        return new ResponseEntity<>(code, message, data);
    }
    public static <T> ResponseEntity<T> success(String message, T data) {
        return success("200", message, data);
    }

    public static <T> ResponseEntity<T> success(T data) {
        return success("操作成功", data);
    }

    private static <T> ResponseEntity<T> error(String code, String message, T data) {
        return new ResponseEntity<>(code, message, data);
    }
    public static <T> ResponseEntity<T> error(String message, T data) {
        return success("0", message, data);
    }

    public static <T> ResponseEntity<T> error(T data) {
        return success("操作失败", data);
    }

}
